﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;


public partial class UserPlanWeek_UserPlanWeekAdd : System.Web.UI.Page
{
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    IBussinessLogic dllDepartment = new DepartmentInfoManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    Authentication dllAuthentication = new Authentication();
    VerifyCircuitManager dllVerifyCircuitManager = new VerifyCircuitManager();
    UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
    WeekDateManager dllWeekDateManager = new WeekDateManager();
    Week_RemindofManager dllWeek_RemindofManager = new Week_RemindofManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (!IsPostBack)
        {
            bindDropDownList(this.drpYear);
            bindDropDownList(this.drpQuarterDate);
            bindDropDownList(this.drpMonthDate);
            bindDropDownList(this.drpWeekDate);
            bindDropDownList(this.drpDepartment);
           
            bindWeekPlan();
            BindDefault();
        }
    }

    void BindDefault()
    {
        //默认绑定责任部门文本框
        this.txtMasterDepartment.Text = this.drpDepartment.SelectedItem.Text;
        object[] _value = new object[1];
        _value[0] = objUserInfo.UserName;
        DataTable _departmentManager = dllUserInfo.get(UserInfoManager.field.IsDepartmentManager.ToString(), _value);
        if (_departmentManager.Rows.Count > 0)
        {
            this.txtEvaluatePeople.Value = _departmentManager.Rows[0]["RealName"].ToString();
        }
        this.txtWeekPlanSortId.Value = Convert.ToString(this.gdvWeekPlan.Rows.Count + 1);
        this.txtSlaveDepartment.Value = "独立完成";
    }


    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");
    }

   


    /// <summary>
    /// 创建空DataTable用于绑定GridView
    /// </summary>
    /// <returns></returns>
    DataTable createDataTable()
    {
        DataTable _dataTable = new DataTable();
        _dataTable.Columns.Add("WeekPlanId");
        _dataTable.Columns.Add("WeekPlanSortId");
        _dataTable.Columns.Add("Source");
        _dataTable.Columns.Add("CompleteTime");
        _dataTable.Columns.Add("WorkItem");
        _dataTable.Columns.Add("MasterDepartment");
        _dataTable.Columns.Add("MasterPeople");
        _dataTable.Columns.Add("SlaveDepartment");
        _dataTable.Columns.Add("SlaveDepartmentDuty");
        _dataTable.Columns.Add("EvaluatePeople");
        _dataTable.Columns.Add("Remart");
        _dataTable.Columns.Add("PlanSendState");
        _dataTable.Columns.Add("MonthPlanId");
        _dataTable.Columns.Add("PlanStep");
        return _dataTable;
    }


    /// <summary>
    /// 绑定空记录表头gridview
    /// </summary>
    void bindWeekPlan()
    {
        object[] _value = new object[2];
        _value[0] = objUserInfo.UserName;
        _value[1] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
        DataTable _weekPlan = dllUserPlanWeek.getUserWeekPlanBySponsorAndWeekDate(_value);
        DataView dv = new DataView(_weekPlan);
        dv.Sort = "WeekPlanSortId";
        this.gdvWeekPlan.DataSource = dv;
        this.gdvWeekPlan.DataBind();
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            LinkButton lbtn = (LinkButton)gdvWeekPlan.Rows[i].Cells[1].FindControl("lbtnSource");
            lbtn.Text = gdvWeekPlan.DataKeys[i]["Source"].ToString();
            wrapByComma(this.gdvWeekPlan, i, 7);
            wrapByComma(this.gdvWeekPlan, i, 8);
            this.gdvWeekPlan.Rows[i].Cells[11].Text = this.gdvWeekPlan.Rows[i].Cells[11].Text.Replace("&", "");
            this.gdvWeekPlan.Rows[i].Cells[11].Text = this.gdvWeekPlan.Rows[i].Cells[11].Text.Replace("nbsp;", "");
            this.gdvWeekPlan.Rows[i].Cells[11].Text = this.gdvWeekPlan.Rows[i].Cells[11].Text.Replace("amp;", "");
            this.gdvWeekPlan.Rows[i].Cells[9].Text = this.gdvWeekPlan.Rows[i].Cells[9].Text.Replace("&", "");
            this.gdvWeekPlan.Rows[i].Cells[9].Text = this.gdvWeekPlan.Rows[i].Cells[9].Text.Replace("nbsp;", "");
            this.gdvWeekPlan.Rows[i].Cells[9].Text = this.gdvWeekPlan.Rows[i].Cells[9].Text.Replace("amp;", "");
            if (gdvWeekPlan.DataKeys[i]["PlanSendState"] != "&nbsp;" && gdvWeekPlan.DataKeys[i]["PlanSendState"] != "")
            {
                if (Convert.ToInt32(gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString()) == 1 || Convert.ToInt32(gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString()) == 2)
                {
                    gdvWeekPlan.Rows[i].BackColor = System.Drawing.Color.Pink;
                }
            }
        }
        this.txtWeekPlanSortId.Value = Convert.ToString(this.gdvWeekPlan.Rows.Count + 1);
    }


    /// <summary>
    /// 验证是否为空
    /// </summary>
    /// <returns></returns>
    string isNull()
    {
        #region  验证是否为空
        if (this.txtCompleteTime.Text.Length == 0)
        {
            return "完成时间不可以为空！";
        }
        if (this.txtMasterPeople.Value.Length == 0)
        {
            return "负责人不可以为空！";
        }
        if (this.txtWorkItem.Text.Length == 0)
        {
            return "工作项不可以为空！";
        }
        if (this.txtSlaveDepartment.Value.Length == 0)
        {
            return "配合部门不可以为空！";
        }
        if (this.txtSlaveDepartmentDuty.Text.Length < 18 && this.txtSlaveDepartment.Value != "独立完成")
        {
            return "配合部门责任不得少于18个字节！";
        }
        if (this.txtEvaluatePeople.Value.Length == 0)
        {
            return "评估人不可以为空！";
        }
        return "";
        #endregion
    }

    /// <summary>
    /// 时间验证
    /// </summary>
    bool verifyDate()
    {
        #region 必要验证判断
        //判断完成时间是否大于起始时间
        object[] _value = new object[1];
        _value[0] = Convert.ToInt32(this.drpWeekDate.SelectedItem.Value);
        DataTable _weekDate = dllWeekDateManager.get(WeekDateManager.field.Week_Id.ToString(), _value);
        if (_weekDate.Rows.Count > 0)
        {

            DateTime _startTime = Convert.ToDateTime(_weekDate.Rows[0]["WeekStartDay"].ToString());
            DateTime _endTime = Convert.ToDateTime(this.txtCompleteTime.Text.Trim());
            if (!dllAuthentication.IsEndTimeGreaterThanStartTime(_startTime, _endTime))
            {
                Utility.HttpHelp.alert("完成时间需要大于周起始时间", Page);
                return false;
            }

        }
        return true;
        #endregion
    }

    /// <summary>
    /// 增加一行事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string _isnull = isNull();
        if (_isnull.Length > 0)
        {
            Utility.HttpHelp.alert(_isnull, Page);
        }
        else
        {
            if (this.txtPlanStep.Text.Trim().Length == 0 || this.txtPlanStep.Text.Trim().Length < 18)
            {
                Utility.HttpHelp.alert("实施步骤不得少于18个字节！", this.Page);
                return;
            }
            if (Convert.ToInt32(this.txtWeekPlanSortId.Value) == 0)
            {
                Utility.HttpHelp.alert("计划编号只能从1开始！", Page);
                return;
            }
            if (!verifyDate())
            {
                return;
            }
            if (this.txtMasterPeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("责任人不可为多人！", Page);
                return;
            }
            if (this.txtEvaluatePeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("评估人不可为多人！", Page);
                return;
            }
            if (this.txtSlaveDepartment.Value != "独立完成")
            {
                if (this.txtSlaveDepartmentDuty.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("配合部门责任字数不得低于32个字符", Page);
                    return;
                }
            }

            ListItem _li = this.drpWeekDate.SelectedItem;
            if (_li.Text == "无周周期")
            {
                Utility.HttpHelp.alert("请选择周周期", Page);
                return;
            }


            DataTable _weekPlan = createDataTable();
            //获取当前gridview的内容导入到datatable
            for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
            {
                DataRow _drGridView = _weekPlan.NewRow();
                _drGridView["WeekPlanId"] = this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString();
                _drGridView["WeekPlanSortId"] =  this.gdvWeekPlan.Rows[i].Cells[1].Text.ToString() ;
                _drGridView["Source"] = ((LinkButton)gdvWeekPlan.Rows[i].Cells[4].FindControl("lbtnSource")).Text;
                _drGridView["CompleteTime"] = this.gdvWeekPlan.Rows[i].Cells[5].Text.ToString();
                _drGridView["WorkItem"] = this.gdvWeekPlan.Rows[i].Cells[2].Text.ToString();
                _drGridView["MasterDepartment"] = this.gdvWeekPlan.Rows[i].Cells[6].Text.ToString();
                _drGridView["MasterPeople"] = this.gdvWeekPlan.Rows[i].Cells[7].Text.ToString();
                _drGridView["SlaveDepartment"] = this.gdvWeekPlan.Rows[i].Cells[8].Text.ToString();
                _drGridView["SlaveDepartmentDuty"] = this.gdvWeekPlan.Rows[i].Cells[9].Text.ToString();
                _drGridView["EvaluatePeople"] = this.gdvWeekPlan.Rows[i].Cells[10].Text.ToString();
                _drGridView["Remart"] = this.gdvWeekPlan.Rows[i].Cells[11].Text.ToString();
                _drGridView["PlanSendState"] = this.gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString();
                _drGridView["MonthPlanId"] = this.gdvWeekPlan.DataKeys[i]["MonthPlanId"].ToString();
                _drGridView["PlanStep"] = this.gdvWeekPlan.Rows[i].Cells[3].Text.ToString();
                
                #region 去除特殊符号如&nbsp;
                _drGridView["WeekPlanId"] = _drGridView["WeekPlanId"].ToString().Replace("&", "");
                _drGridView["WeekPlanId"] = _drGridView["WeekPlanId"].ToString().Replace("nbsp;", "");
                _drGridView["PlanSendState"] = _drGridView["PlanSendState"].ToString().Replace("&", "");
                _drGridView["PlanSendState"] = _drGridView["PlanSendState"].ToString().Replace("nbsp;", "");
                _drGridView["WeekPlanSortId"] = _drGridView["WeekPlanSortId"].ToString().Replace("&", "");
                _drGridView["WeekPlanSortId"] = _drGridView["WeekPlanSortId"].ToString().Replace("nbsp;", "");
                _drGridView["Source"] = _drGridView["Source"].ToString().Replace("&", "");
                _drGridView["Source"] = _drGridView["Source"].ToString().Replace("nbsp;", "");
                _drGridView["CompleteTime"] = _drGridView["CompleteTime"].ToString().Replace("&", "");
                _drGridView["CompleteTime"] = _drGridView["CompleteTime"].ToString().Replace("nbsp;", "");
                _drGridView["WorkItem"] = _drGridView["WorkItem"].ToString().Replace("&", "");
                _drGridView["WorkItem"] = _drGridView["WorkItem"].ToString().Replace("nbsp;", "");

                _drGridView["MasterDepartment"] = _drGridView["MasterDepartment"].ToString().Replace("&", "");
                _drGridView["MasterDepartment"] = _drGridView["MasterDepartment"].ToString().Replace("nbsp;", "");
                _drGridView["MasterPeople"] = _drGridView["MasterPeople"].ToString().Replace("&", "");
                _drGridView["MasterPeople"] = _drGridView["MasterPeople"].ToString().Replace("nbsp;", "");
                _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace("&", "");
                _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace("nbsp;", "");
                _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace(",<br>", ",");

                _drGridView["SlaveDepartmentDuty"] = _drGridView["SlaveDepartmentDuty"].ToString().Replace("&", "");
                _drGridView["SlaveDepartmentDuty"] = _drGridView["SlaveDepartmentDuty"].ToString().Replace("nbsp;", "");
                _drGridView["EvaluatePeople"] = _drGridView["EvaluatePeople"].ToString().Replace("&", "");
                _drGridView["EvaluatePeople"] = _drGridView["EvaluatePeople"].ToString().Replace("nbsp;", "");
                _drGridView["Remart"] = _drGridView["Remart"].ToString().Replace("&", "");
                _drGridView["Remart"] = _drGridView["Remart"].ToString().Replace("nbsp;", "");
                _drGridView["PlanStep"] = _drGridView["PlanStep"].ToString().Replace("&", "");
                _drGridView["PlanStep"] = _drGridView["PlanStep"].ToString().Replace("nbsp;", "");
                _weekPlan.Rows.Add(_drGridView);
                #endregion
            }
            //获取当前添加的信息内容
            DataRow _drTable = _weekPlan.NewRow();
            _drTable["WeekPlanSortId"] = this.txtWeekPlanSortId.Value.Trim() ;
            _drTable["Source"] = this.drpSource.SelectedItem.Text;
            _drTable["CompleteTime"] = this.txtCompleteTime.Text.Trim();
            _drTable["WorkItem"] = this.txtWorkItem.Text.Trim();
            _drTable["MasterDepartment"] = this.drpDepartment.SelectedItem.Text;
            _drTable["MasterPeople"] = this.txtMasterPeople.Value.Trim();
            _drTable["SlaveDepartment"] = this.txtSlaveDepartment.Value.Trim();
            _drTable["SlaveDepartmentDuty"] = this.txtSlaveDepartmentDuty.Text.Trim();
            _drTable["EvaluatePeople"] = this.txtEvaluatePeople.Value.Trim();
            _drTable["MonthPlanId"] = "";
            _drTable["Remart"] = this.txtRemark.Text;
            _drTable["PlanStep"] = this.txtPlanStep.Text;
            _weekPlan.Rows.Add(_drTable);
            DataView dv = new DataView(_weekPlan);
            dv.Sort = "WeekPlanSortId";
            this.gdvWeekPlan.DataSource = dv;
            this.gdvWeekPlan.DataBind();


            for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
            {
                LinkButton lbtn = (LinkButton)gdvWeekPlan.Rows[i].Cells[4].FindControl("lbtnSource");
                lbtn.Text = gdvWeekPlan.DataKeys[i]["Source"].ToString();
                wrapByComma(this.gdvWeekPlan, i, 7);
                wrapByComma(this.gdvWeekPlan, i, 8);
            }
            #region 善后操作
            //将文本框清空
            this.txtWeekPlanSortId.Value = Convert.ToString(this.gdvWeekPlan.Rows.Count + 1);
            this.txtCompleteTime.Text = "";
            //this.txtMasterPeople.Value = "";
            this.txtRemark.Text = "";
            this.txtSlaveDepartment.Value = "";
            this.txtSlaveDepartmentDuty.Text = "";
            this.txtPlanStep.Text = "";
            this.txtEvaluatePeople.Value = "";
            this.txtWorkItem.Text = "";
            
            bindDropDownList(this.drpDepartment);
            #endregion
            addWeekPlan1(0);
            bindWeekPlan();
        }
        BindDefault();
        bindDropDownList(this.drpDepartment);
    }


    /// <summary>
    /// 添加周计划方法
    /// </summary>
    /// <param name="state">0草稿 1 提交</param>    
    void addWeekPlan1(int state)
    {
        #region 参数
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        //得到参数 部门名称的DataTable
        object[] _valueDepartmentName = new object[1];
        _valueDepartmentName[0] = this.drpDepartment.SelectedItem.Text;
        DataTable _VerifyCircuitId = dllVerifyCircuitManager.getVerifyCircuitIdByDepartment(_valueDepartmentName);
        if (_VerifyCircuitId.Rows.Count == 0)
        {
            Utility.Error.RedirectErrorPage("所在部门无计划流程，请重试");
        }


        //获取登录用户名
        Model.UserInfo objUserInfo = new Model.UserInfo();
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {

            CheckBox _ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            //if (_ckb.Checked == true)
            //{
                _count++;
                if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length == 0 || this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString() == "&nbsp;")
                {
                    object[] _value = new object[18];
                    //完成时间
                    _value[0] = Convert.ToDateTime(this.gdvWeekPlan.Rows[i].Cells[5].Text.Trim());
                    //工作内容
                    _value[1] = this.gdvWeekPlan.Rows[i].Cells[2].Text.Trim();
                    //实施步骤
                    _value[2] = this.gdvWeekPlan.Rows[i].Cells[3].Text.Trim();
                    //责任部门
                    _value[3] = this.gdvWeekPlan.Rows[i].Cells[6].Text.Trim();
                    //责任人
                    _value[4] = this.gdvWeekPlan.Rows[i].Cells[7].Text.Trim();
                    //配合部门
                    _value[5] = this.gdvWeekPlan.Rows[i].Cells[8].Text.Trim().Replace("<br>", ",");
                    //配合部门责任
                    _value[6] = this.gdvWeekPlan.Rows[i].Cells[9].Text.Trim();
                    _value[7] = state;//发送状态
                    _value[8] = 0;//是否达成共识
                    _value[9] = this.gdvWeekPlan.Rows[i].Cells[11].Text.Trim(); ;//Remart
                    _value[10] = Convert.ToInt32(this.drpWeekDate.SelectedValue);//weekDate
                    _value[11] = Convert.ToInt32(_VerifyCircuitId.Rows[0]["VerifyCircuitId"].ToString());

                    //获取选择责任人
                    _value[12] = objUserInfo.UserName;
                    //_value[12] = objUserInfo.UserName;//发起人
                    _value[13] = this.gdvWeekPlan.Rows[i].Cells[10].Text.Trim();//评估人
                    _value[14] =  this.gdvWeekPlan.Rows[i].Cells[1].Text ;
                    _value[15] = gdvWeekPlan.DataKeys[i]["Source"].ToString();
                    _value[16] = 0;
                    _value[17] = 0;
                    _valueList.Add(_value);
                }
            //}
        }
        #endregion
        if (_count <= 0)
        {
            Utility.HttpHelp.alert("请选择要保存的计划", Page);
            return;
        }
        if (_valueList.Count == 0)
        {
            Utility.HttpHelp.alert("选择的计划已保存", Page);
        }
        if (_valueList.Count > 0)
        {
            int result = dllUserPlanWeek.addWithTransaction(_valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("添加周计划未成功，请重试！");
            }
            #region 善后操作
            //将文本框清空
            this.txtWeekPlanSortId.Value = this.gdvWeekPlan.Rows.Count.ToString();
            this.txtCompleteTime.Text = "";
            this.txtMasterPeople.Value = "";
            this.txtRemark.Text = "";
            this.txtSlaveDepartment.Value = "";
            this.txtSlaveDepartmentDuty.Text = "";

            this.txtEvaluatePeople.Value = "";
            this.txtWorkItem.Text = "";
            #endregion
        }
    }


    /// <summary>
    /// 添加周计划方法
    /// </summary>
    /// <param name="state">0草稿 1 提交</param>    
    void addWeekPlan(int state)
    {
        #region 参数
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        //得到参数 部门名称的DataTable
        object[] _valueDepartmentName = new object[1];
        _valueDepartmentName[0] = this.drpDepartment.SelectedItem.Text;
        DataTable _VerifyCircuitId = dllVerifyCircuitManager.getVerifyCircuitIdByDepartment(_valueDepartmentName);
        if (_VerifyCircuitId.Rows.Count == 0)
        {
            Utility.Error.RedirectErrorPage("所在部门无计划流程，请重试");
        }


        //获取登录用户名
        Model.UserInfo objUserInfo = new Model.UserInfo();
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {

            CheckBox _ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (_ckb.Checked == true)
            {
            _count++;
            if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length == 0 || this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString() == "&nbsp;")
            {
                object[] _value = new object[18];
                //完成时间
                _value[0] = Convert.ToDateTime(this.gdvWeekPlan.Rows[i].Cells[5].Text.Trim());
                //工作内容
                _value[1] = this.gdvWeekPlan.Rows[i].Cells[2].Text.Trim();
                //实施步骤
                _value[2] = this.gdvWeekPlan.Rows[i].Cells[3].Text.Trim();
                //责任部门
                _value[3] = this.gdvWeekPlan.Rows[i].Cells[6].Text.Trim();
                //责任人
                _value[4] = this.gdvWeekPlan.Rows[i].Cells[7].Text.Trim();
                //配合部门
                _value[5] = this.gdvWeekPlan.Rows[i].Cells[8].Text.Trim().Replace("<br>", ",");
                //配合部门责任
                _value[6] = this.gdvWeekPlan.Rows[i].Cells[9].Text.Trim();
                _value[7] = state;//发送状态
                _value[8] = 0;//是否达成共识
                _value[9] = this.gdvWeekPlan.Rows[i].Cells[11].Text.Trim(); ;//Remart
                _value[10] = Convert.ToInt32(this.drpWeekDate.SelectedValue);//weekDate
                _value[11] = Convert.ToInt32(_VerifyCircuitId.Rows[0]["VerifyCircuitId"].ToString());

                //获取选择责任人
                _value[12] = objUserInfo.UserName;
                //_value[12] = objUserInfo.UserName;//发起人
                _value[13] = this.gdvWeekPlan.Rows[i].Cells[10].Text.Trim();//评估人
                _value[14] =  this.gdvWeekPlan.Rows[i].Cells[1].Text ;
                _value[15] = gdvWeekPlan.DataKeys[i]["Source"].ToString();
                _value[16] = 0;
                _value[17] = 0;
                _valueList.Add(_value);
            }
            }
        }
        #endregion
        if (_count <= 0)
        {
            Utility.HttpHelp.alert("请选择要保存的计划", Page);
            return;
        }
        if (_valueList.Count == 0)
        {
            Utility.HttpHelp.alert("选择的计划已保存", Page);
        }
        if (_valueList.Count > 0)
        {
            int result = dllUserPlanWeek.addWithTransaction(_valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("添加周计划未成功，请重试！");
            }
            #region 善后操作
            //将文本框清空
            this.txtWeekPlanSortId.Value = this.gdvWeekPlan.Rows.Count.ToString();
            this.txtCompleteTime.Text = "";
            this.txtMasterPeople.Value = "";
            this.txtRemark.Text = "";
            this.txtSlaveDepartment.Value = "";
            this.txtSlaveDepartmentDuty.Text = "";

            this.txtEvaluatePeople.Value = "";
            this.txtWorkItem.Text = "";
            #endregion
        }
    }


    /// <summary>
    /// 提交周计划方法
    /// </summary>
    /// <param name="state">0草稿 1 提交</param>    
    void submitWeekPlan(int state)
    {
        #region 参数
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        //得到参数 部门名称的DataTable
        object[] _valueDepartmentName = new object[1];
        _valueDepartmentName[0] = this.drpDepartment.SelectedItem.Text;
        DataTable _VerifyCircuitId = dllVerifyCircuitManager.getVerifyCircuitIdByDepartment(_valueDepartmentName);
        if (_VerifyCircuitId.Rows.Count == 0)
        {
            Utility.Error.RedirectErrorPage("所在部门无计划流程，请重试");
        }


        //获取登录用户名
        Model.UserInfo objUserInfo = new Model.UserInfo();
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {

            CheckBox _ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (_ckb.Checked == true)
            {
                _count++;
                if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length == 0 || this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString() == "&nbsp;")
                {
                    object[] _value = new object[18];
                    //完成时间
                    _value[0] = Convert.ToDateTime(this.gdvWeekPlan.Rows[i].Cells[5].Text.Trim());
                    //工作内容
                    _value[1] = this.gdvWeekPlan.Rows[i].Cells[2].Text.Trim();
                    //实施步骤
                    _value[2] = this.gdvWeekPlan.Rows[i].Cells[3].Text.Trim();
                    //责任部门
                    _value[3] = this.gdvWeekPlan.Rows[i].Cells[6].Text.Trim();
                    //责任人
                    _value[4] = this.gdvWeekPlan.Rows[i].Cells[7].Text.Trim();
                    //配合部门
                    _value[5] = this.gdvWeekPlan.Rows[i].Cells[8].Text.Trim().Replace("<br>", ",");
                    //配合部门责任
                    _value[6] = this.gdvWeekPlan.Rows[i].Cells[9].Text.Trim();
                    _value[7] = state;//发送状态
                    _value[8] = 0;//是否达成共识
                    _value[9] = this.gdvWeekPlan.Rows[i].Cells[11].Text.Trim(); ;//Remart
                    _value[10] = Convert.ToInt32(this.drpWeekDate.SelectedValue);//weekDate
                    _value[11] = Convert.ToInt32(_VerifyCircuitId.Rows[0]["VerifyCircuitId"].ToString());

                    //获取选择责任人
                    _value[12] = objUserInfo.UserName;
                    //_value[12] = objUserInfo.UserName;//发起人
                    _value[13] = this.gdvWeekPlan.Rows[i].Cells[10].Text.Trim();//评估人
                    _value[14] =  this.gdvWeekPlan.Rows[i].Cells[1].Text ;
                    _value[15] = gdvWeekPlan.DataKeys[i]["Source"].ToString();
                    _value[16] = 0;
                    _value[17] = 0;
                    _valueList.Add(_value);
                }
                else
                {
                    if (Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString()) == 0 || Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString()) == -1)
                    {
                        string a = this.gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString();
                        if (Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString()) == 0 || Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString()) == -1)
                        {
                            editWeekPlan(Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString()));
                        }
                    }
                }
            }
        }
        #endregion
        if (_count <= 0)
        {
            Utility.HttpHelp.alert("请选择要保存的计划", Page);
            return;
        }
        if (_valueList.Count > 0)
        {
            int result = dllUserPlanWeek.addWithTransaction(_valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("提交周计划未成功，请重试！");
            }
            else
            {
                Utility.HttpHelp.alert("提交成功", Page);
            }
            #region 善后操作
            //将文本框清空
            this.txtWeekPlanSortId.Value = this.gdvWeekPlan.Rows.Count.ToString();
            this.txtCompleteTime.Text = "";
            this.txtMasterPeople.Value = "";
            this.txtRemark.Text = "";
            this.txtSlaveDepartment.Value = "";
            this.txtSlaveDepartmentDuty.Text = "";

            this.txtEvaluatePeople.Value = "";
            this.txtWorkItem.Text = "";
            #endregion
        }
    }



    /// <summary>
    /// 保存按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        addWeekPlan(0);
        bindWeekPlan();
        //清除全选按钮状态
        // //默认绑定责任部门文本框
        this.txtMasterDepartment.Text = this.drpDepartment.SelectedItem.Text;
        object[] _value = new object[1];
        _value[0] = objUserInfo.UserName;
        DataTable _departmentManager = dllUserInfo.get(UserInfoManager.field.IsDepartmentManager.ToString(), _value);
        if (_departmentManager.Rows.Count > 0)
        {
            this.txtEvaluatePeople.Value = _departmentManager.Rows[0]["RealName"].ToString();
        }
        bindDropDownList(this.drpDepartment);
        this.ckbAllSelect.Checked = false;
        #region 善后操作
        BindDefault();
        #endregion
    }


    /// <summary>
    /// 修改周计划方法
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-3-7</date>
    void editWeekPlan(int _weekPlanId)
    {
        object[] _value = new object[1];
        _value[0] = _weekPlanId;
        int result = dllUserPlanWeek.edit(UserPlanWeek.field.PlanSendState.ToString(), _value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("提交周计划未成功，请重试！");
        }
        #region 善后操作
        //将文本框清空
        this.txtWeekPlanSortId.Value = Convert.ToString(this.gdvWeekPlan.Rows.Count + 1);
        this.txtCompleteTime.Text = "";
        this.txtMasterPeople.Value = "";
        this.txtRemark.Text = "";
        this.txtSlaveDepartment.Value = "";
        this.txtSlaveDepartmentDuty.Text = "";

        this.txtEvaluatePeople.Value = "";
        this.txtWorkItem.Text = "";
        #endregion
    }

    /// <summary>
    /// 提交按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        submitWeekPlan(1);
        bindWeekPlan();
       
        bindDropDownList(this.drpDepartment);
        BindDefault();
    }


    #region DropDownList改变事件
    /// <summary>
    /// 绑定所有的dropdownlist
    /// </summary>
    /// <param name="_drp"></param>
    void bindDropDownList(DropDownList _drp)
    {//部门绑定
        if (_drp.Equals(this.drpDepartment))
        {
            object[] _value = new object[1];
            Model.UserInfo objUserInfo = new Model.UserInfo();
            _value[0] = objUserInfo.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _value);
            if (_userTable.Rows.Count > 0)
            {
                if (_userTable.Rows[0]["DepartmentId"].ToString().Length > 0)
                {
                    ListItem _li = new ListItem(_userTable.Rows[0]["DepartmentId"].ToString());
                    this.drpDepartment.Items.Add(_li);
                }
                if (_userTable.Rows[0]["PartTimeDepartmentId"].ToString().Length > 0)
                {
                    ListItem _li = new ListItem(_userTable.Rows[0]["PartTimeDepartmentId"].ToString());
                    this.drpDepartment.Items.Add(_li);
                }
                //同时绑定责任人
                this.txtMasterPeople.Value = _userTable.Rows[0]["RealName"].ToString();
            }
        }
        //年份绑定
        if (_drp.Equals(this.drpYear))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            string _year = DateTime.Now.Year.ToString();
            this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));

        }

        //绑定年计划周期
        if (_drp.Equals(this.drpQuarterDate))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYear.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDate.DataSource = _quarter;
                this.drpQuarterDate.DataTextField = "QuarterName";
                this.drpQuarterDate.DataValueField = "Quarter_Id";
                this.drpQuarterDate.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                //根据系统当前日期查找到对应的年周期
                DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                if (_quartertime.Rows.Count >0)
                {
                    this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_quartertime.Rows[0][1].ToString()));                    
                }
                #endregion
                bindDropDownList(this.drpMonthDate);
            }
            else
            {
                ListItem _li = new ListItem("无年周期", "0");
                this.drpQuarterDate.Items.Clear();
                this.drpQuarterDate.Items.Add(_li);
                bindDropDownList(this.drpMonthDate);
            }

        }

        //绑定月计划周期
        if (_drp.Equals(this.drpMonthDate))
        {
            object[] _value = new object[2];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {
                this.drpMonthDate.DataSource = _month;
                this.drpMonthDate.DataTextField = "MonthName";
                this.drpMonthDate.DataValueField = "Month_Id";
                this.drpMonthDate.DataBind();
                #region 根据系统当前日期绑定到当前月周期
                DataTable _monthtime = dllMonthDateManager.getMonthDate();
                if (_monthtime.Rows.Count >0)
                {
                    this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByText(_monthtime.Rows[0][3].ToString()));                   

                }
                #endregion
                bindDropDownList(this.drpWeekDate);
            }
            else
            {
                ListItem _li = new ListItem("无月周期", "0");
                this.drpMonthDate.Items.Clear();
                this.drpMonthDate.Items.Add(_li);
                bindDropDownList(this.drpWeekDate);
            }

        }
        //绑定周计划周期
        if (_drp.Equals(this.drpWeekDate))
        {
            object[] _value = new object[3];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            _value[2] = this.drpMonthDate.SelectedItem.Text;
            DataTable _week = dllWeekDateManager.get(WeekDateManager.field.MonthName.ToString(), _value);
            if (_week.Rows.Count != 0)
            {
                this.drpWeekDate.DataSource = _week;
                this.drpWeekDate.DataTextField = "WeekName";
                this.drpWeekDate.DataValueField = "Week_Id";
                this.drpWeekDate.DataBind();
                DataTable _weektime = dllWeekDateManager.getWeekDate();
                if (_weektime.Rows.Count>0)
                {
                    this.drpWeekDate.SelectedIndex = this.drpWeekDate.Items.IndexOf(this.drpWeekDate.Items.FindByText(_weektime.Rows[0][4].ToString()));                   
                }
                bindWeekPlan();
            }
            else
            {
                ListItem _li = new ListItem("无周周期", "0");
                this.drpWeekDate.Items.Clear();
                this.drpWeekDate.Items.Add(_li);
                bindWeekPlan();
            }
        }

    }
    /// <summary>
    /// 年的Dropdownlist改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDate);
        bindDropDownList(this.drpMonthDate);
        bindDropDownList(this.drpWeekDate);


    }
    /// <summary>
    /// 年周期的dropdownlist改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDate);
        bindDropDownList(this.drpWeekDate);
    }
    /// <summary>
    /// 月周期的dropdownlist
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpWeekDate);
    }
    /// <summary>
    /// 周周期的dropdownlist改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpWeekDate_SelectedIndexChanged(object sender, EventArgs e)
    {        
        bindWeekPlan();
    }
    #endregion


    /// <summary>
    /// 全选事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ckbAllSelect_CheckedChanged(object sender, EventArgs e)
    {
        if (this.ckbAllSelect.Checked == true)
        {
            for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
            {
                CheckBox _chk = ((CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect"));
                _chk.Checked = true;
            }
        }
        else
        {
            for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
            {
                CheckBox _chk = ((CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect"));
                _chk.Checked = false;
            }
        }
    }


    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDel_Click(object sender, EventArgs e)
    {
        //得到button所在行        
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        int _rowIndex = iRow.RowIndex;//得到该行的索引


        //遍历GridView将GridView转为DataTable
        DataTable _weekPlan = createDataTable();
        //获取GridView当前内容导入DataTable

        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            DataRow _drGridView = _weekPlan.NewRow();

            _drGridView["WeekPlanId"] = this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString();
            _drGridView["Source"] = this.gdvWeekPlan.Rows[i].Cells[4].Text.ToString();
            _drGridView["CompleteTime"] = this.gdvWeekPlan.Rows[i].Cells[2].Text.ToString();
            _drGridView["WorkItem"] = this.gdvWeekPlan.Rows[i].Cells[3].Text.ToString();
            _drGridView["MasterDepartment"] = this.gdvWeekPlan.Rows[i].Cells[5].Text.ToString();
            _drGridView["MasterPeople"] = this.gdvWeekPlan.Rows[i].Cells[6].Text.ToString();
            _drGridView["SlaveDepartment"] = this.gdvWeekPlan.Rows[i].Cells[7].Text.ToString();
            _drGridView["SlaveDepartmentDuty"] = this.gdvWeekPlan.Rows[i].Cells[8].Text.ToString();
            _drGridView["EvaluatePeople"] = this.gdvWeekPlan.Rows[i].Cells[9].Text.ToString();
            _drGridView["Remart"] = this.gdvWeekPlan.Rows[i].Cells[10].Text.ToString();
            _drGridView["WeekPlanSortId"] = this.gdvWeekPlan.Rows[i].Cells[1].Text.ToString();
            _drGridView["PlanSendState"] = this.gdvWeekPlan.DataKeys[i]["PlanSendState"].ToString();

            #region 去除特殊符号如&nbsp;
            _drGridView["WeekPlanId"] = _drGridView["WeekPlanId"].ToString().Replace("&", "");
            _drGridView["WeekPlanId"] = _drGridView["WeekPlanId"].ToString().Replace("nbsp;", "");
            _drGridView["PlanSendState"] = _drGridView["PlanSendState"].ToString().Replace("&", "");
            _drGridView["PlanSendState"] = _drGridView["PlanSendState"].ToString().Replace("nbsp;", "");
            _drGridView["WeekPlanSortId"] = _drGridView["WeekPlanSortId"].ToString().Replace("&", "");
            _drGridView["WeekPlanSortId"] = _drGridView["WeekPlanSortId"].ToString().Replace("nbsp;", "");
            _drGridView["Source"] = _drGridView["Source"].ToString().Replace("&", "");
            _drGridView["Source"] = _drGridView["Source"].ToString().Replace("nbsp;", "");
            _drGridView["CompleteTime"] = _drGridView["CompleteTime"].ToString().Replace("&", "");
            _drGridView["CompleteTime"] = _drGridView["CompleteTime"].ToString().Replace("nbsp;", "");
            _drGridView["WorkItem"] = _drGridView["WorkItem"].ToString().Replace("&", "");
            _drGridView["WorkItem"] = _drGridView["WorkItem"].ToString().Replace("nbsp;", "");

            _drGridView["MasterDepartment"] = _drGridView["MasterDepartment"].ToString().Replace("&", "");
            _drGridView["MasterDepartment"] = _drGridView["MasterDepartment"].ToString().Replace("nbsp;", "");
            _drGridView["MasterPeople"] = _drGridView["MasterPeople"].ToString().Replace("&", "");
            _drGridView["MasterPeople"] = _drGridView["MasterPeople"].ToString().Replace("nbsp;", "");
            _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace("&", "");
            _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace("nbsp;", "");
            _drGridView["SlaveDepartment"] = _drGridView["SlaveDepartment"].ToString().Replace(",<br>", ",");

            _drGridView["SlaveDepartmentDuty"] = _drGridView["SlaveDepartmentDuty"].ToString().Replace("&", "");
            _drGridView["SlaveDepartmentDuty"] = _drGridView["SlaveDepartmentDuty"].ToString().Replace("nbsp;", "");
            _drGridView["EvaluatePeople"] = _drGridView["EvaluatePeople"].ToString().Replace("&", "");
            _drGridView["EvaluatePeople"] = _drGridView["EvaluatePeople"].ToString().Replace("nbsp;", "");
            _drGridView["Remart"] = _drGridView["Remart"].ToString().Replace("&", "");
            _drGridView["Remart"] = _drGridView["Remart"].ToString().Replace("nbsp;", "");
            #endregion

            _weekPlan.Rows.Add(_drGridView);
        }

        //计划如果被保存为草稿，也同时删除        
        if (this.gdvWeekPlan.DataKeys[_rowIndex]["WeekPlanId"].ToString() != "&nbsp;" && this.gdvWeekPlan.DataKeys[_rowIndex]["WeekPlanId"].ToString().Length > 0)
        {
            if (Convert.ToInt32(this.gdvWeekPlan.DataKeys[_rowIndex]["PlanSendState"].ToString()) != 0)
            {
                Utility.HttpHelp.alert("已提交的计划不可以删除", Page);
                return;
            }
            _weekPlan.Rows[_rowIndex].Delete();
            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(this.gdvWeekPlan.DataKeys[_rowIndex]["WeekPlanId"].ToString());
            int result =dllUserPlanWeek.del(UserPlanWeek.field.WeekPlanId.ToString(), _value);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("删除周计划未成功，请重试！");
            }

        }
        else
        {
            _weekPlan.Rows[_rowIndex].Delete();
        }
        this.gdvWeekPlan.DataSource = _weekPlan;
        this.gdvWeekPlan.DataBind();
        //隐藏首行，只保留表头
        //this.gdvWeekPlan.Rows[0].Visible = false;
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            wrapByComma(this.gdvWeekPlan, i, 6);
            wrapByComma(this.gdvWeekPlan, i, 7);
        }
    }



    

    /// <summary>
    /// 自动编号
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvWeekRemind_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
        }
    }
    /// <summary>
    /// 上传附件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        string _weekId = "";
        int _count = 0;
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _weekId = this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString();
                _count++;
            }
        }
        if (_count == 1)
        {
            //定向到添加年附件路径页面
            string _url = "../WebCommon/SendAttachmentPath.aspx?PlanId=" + _weekId + "&PlanType=7";
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','quarterplandetailmodify','height=40,width=400,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');</script>");
        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能选择一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
    }


    /// <summary>
    /// 来源事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSource_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行         
        i = iRow.RowIndex;//得到该行的索引
        Control c = (Control)iRow.Parent;
        GridView _gdv = (GridView)c.Parent;
        int _monthPlanId = Convert.ToInt32(_gdv.DataKeys[i]["MonthPlanId"].ToString());
        if (_monthPlanId == 0)
        {
            //新增的不链接页面
        }
        else
        {
            string _url = "MonthPlanDetail.aspx?MonthPlanId=" + _monthPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=160,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
    }
    protected void btnModify_Click(object sender, EventArgs e)
    {
        BLL.UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
        int _count = 0;
        int _weekId = 0;
        for (int i = 0; i < this.gdvWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                if (this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString().Length == 0)
                {
                    Utility.HttpHelp.alert("请保存后在修改！", this.Page);
                    return;
                }
                _weekId = Convert.ToInt32(this.gdvWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                _count++;
            }
        }
        if (_count == 1)
        {
            //判断是否为评估人，如果该条计划的评估人是当前用户则不能修改该条计划

            object[] _value = new object[1];
            _value[0] = _weekId;
            DataTable userweekplan = dllUserPlanWeek.get(UserPlanWeek.field.WeekPlanId.ToString(), _value);
            if (userweekplan.Rows.Count > 0)
            {
                if (Convert.ToInt32(userweekplan.Rows[0]["PlanSendState"]) >= 1)
                {
                    Utility.HttpHelp.alert("计划已提交，不允许修改！", Page);
                    return;
                }
            }


            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[2];
                _username[0] = _userTable.Rows[0]["RealName"].ToString();
                _username[1] = _weekId;
                DataTable _iSEvaluatePeople = dllUserPlanWeek.get(UserPlanWeek.field.EvaluatePeople.ToString(), WeekPlanofManager.field.WeekPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count > 0)
                {
                    Utility.HttpHelp.alert("评估人不能修改计划", Page);
                }
                else
                {
                    ListItem _li = this.drpWeekDate.SelectedItem;
                    if (_li != null)
                    {
                        string _url = "ModifyUserPlanWeek.aspx?Id=" + _weekId + "&Year=" + this.drpYear.SelectedValue + "&QuarterDate=" + this.drpQuarterDate.SelectedValue + "&MonthDate=" + this.drpMonthDate.SelectedValue + "&WeekDate=" + _li.Value + "&url=UserPlanWeekAdd.aspx";
                        Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;
                    }
                }
            }

        }
        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能查看一个周计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
    }
}
